function Question(a) {
    if (a == null) {
        a = {}
    }
    this.showtype = "question";
    this.id = (a.id != null && a.id != "") ? a.id + "": (new Date()).getTime() + "";
    this.type = a.type != null ? a.type: 1;
    this.description = a.description != null ? a.description: (this.type == 0 ? "累的话，可以休息一下...": "");
    this.descriptionview = a.descriptionview != null ? a.descriptionview: (this.type == 0 ? "累的话，可以休息一下...": "");
    this.isgridchildquestion = 0;
    this.pageid = "";
    this.typeid = a.typeid != null ? a.typeid: 1;
    this.fatherquestionid;
    this.format = a.format != null ? a.format: ((a.typeid == 1 && (a.type == 1 || a.type == 2)) ? 8: (a.typeid == 12 ? 4: 1));
    this.randomize = a.randomize != null ? a.randomize: 0;
    this.allowother = a.allowother != null ? a.allowother: 0;
    this.instruction = a.instruction != null ? a.instruction: (this.type == 0 ? "说明内容": "");
    this.predefine = a.predefine != null ? a.predefine: "";
    this.rangemin = a.rangemin != null ? a.rangemin: 0;
    this.rangemax = a.rangemax != null ? a.rangemax: 0;
    this.rangeformat = a.rangeformat != null ? a.rangeformat: 0;
    this.imageurl = a.imageurl != null ? a.imageurl: "";
    this.gridrandomize = a.gridrandomize != null ? a.gridrandomize: 0;
    this.showhasother = a.showhasother != null ? a.showhasother: 0;
    this.showpoint = a.showpoint != null ? a.showpoint: 0;
    this.required = a.required != null ? a.required: 1;
    this.imagetype = a.imagetype != null ? a.imagetype: 2;
    this.imagewidth = a.imagewidth != null ? a.imagewidth: 0;
    this.imageheight = a.imageheight != null ? a.imageheight: 0;
    this.isedit = a.isedit != null ? a.isedit: 0;
    this.answers = new Array();
    if (a.answers != null && a.answers.length > 0) {
        this.answers = a.answers
    } else {
        if (this.type == 1 || this.type == 2 || this.type == 41 || this.type == 42) {
            if (this.typeid == 3) {
                this.answers = getDefaultColorAnswerList()
            } else {
                if (this.typeid == 18) {
                    this.answers = getDefaultPointAnswerList()
                } else {
                    if (this.typeid == 15 || this.typeid == 16 || this.typeid == 17) {} else {
                        this.answers = getDefaultAnswerList()
                    }
                }
            }
        } else {
            if (this.type == 6 && this.typeid == 5) {
                var b = new Array();
                b.push(new Answer({
                    id: (new Date()).getTime() + "",
                    name: "",
                    point: 1
                }));
                this.answers = b
            }
        }
    }
    this.questions = new Array();
    if (a.questions != null && a.questions.length > 0) {
        this.questions = a.questions
    } else {
        if (this.type == 41 || this.type == 42) {
            this.questions = getDefaultQuestionList()
        }
    }
}

// 根据问题类型ID创建问题
function createQuestionByID(a) {
    var b = null;
    if (a == "pagebreak") { //如果创建分页符
        b = new Page({}); // 分页属性
    } else {
        var c = 0;
        if (a == "singleopen" || a == "paragraph") { //创建单行文本 多行文本
            c = 1
        }
        b = new Question({ // 根据问题类型初始化部分参数
            type: QuestionTypeMap[a].type, // 代表问题的形式
            typeid: QuestionTypeMap[a].typeid, //代表问题的分组
            rangeformat: c, // 格式化类型
            description: QuestionTypeMap[a].description, //描述
            descriptionview: QuestionTypeMap[a].description
        });
        // 根据具体类型确定格式化的参数
        if (b.type == 6 && b.typeid == 9) { // 日期
            b.format = 6
        }
        if (b.type == 6 && b.typeid == 12) { // 电话号码
            b.format = 4
        }
    }
    return b;
}
function createQuestion(b, a) {
    var c = null;
    if (b == -1) {
        c = new Page({})
    } else {
        c = new Question({
            type: b,
            typeid: a
        })
    }
    return c
}
function getDefaultAnswerList() {
    var a = new Array();
    a.push(new Answer({
        id: (new Date()).getTime() + "",
        name: "选项1",
        point: 1
    }));
    a.push(new Answer({
        id: ((new Date()).getTime() + 1) + "",
        name: "选项2",
        point: 2
    }));
    a.push(new Answer({
        id: ((new Date()).getTime() + 2) + "",
        name: "选项3",
        point: 3
    }));
    return a
}
function getDefaultQuestionList() {
    var a = new Array();
    a.push(new Question({
        id: (new Date()).getTime() + "",
        description: "子问题1",
        descriptionview: "子问题1"
    }));
    a.push(new Question({
        id: ((new Date()).getTime() + 1) + "",
        description: "子问题2",
        descriptionview: "子问题2"
    }));
    a.push(new Question({
        id: ((new Date()).getTime() + 2) + "",
        description: "子问题3",
        descriptionview: "子问题3"
    }));
    return a
}
function getDefaultColorAnswerList() {
    var d = new Array();
    var e = ColorList.color;
    var a = ColorList.colorName;
    for (var b = 0; b < e.length; b++) {
        d.push(new Answer({
            id: ((new Date()).getTime() + b) + "",
            name: a[b],
            remark: e[b],
            point: b
        }))
    }
    return d
}
function getDefaultPointAnswerList() {
    var b = new Array();
    for (var a = 1; a <= 10; a++) {
        b.push(new Answer({
            id: ((new Date()).getTime() + a) + "",
            name: a,
            value: a,
            point: a
        }))
    }
    return b
}
function getAnswerFromQuestion(d, c) {
    var b = {};
    if (d.answers != null) {
        for (var a = 0; a < d.answers.length; a++) {
            if (d.answers[a].id == c) {
                b = d.answers[a]
            }
        }
    }
    return b
}
function getQuestionFromQuestion(c, d) {
    var a = {};
    if (c.questions != null) {
        for (var b = 0; b < c.questions.length; b++) {
            if (c.questions[b].id == d) {
                a = c.questions[b]
            }
        }
    }
    return a
}
function createSingleOpen() {
    var a = {
        type: 6,
        typeid: 5
    };
    return Question(a)
}
function createParagraph() {
    var a = {
        type: 6,
        typeid: 1
    };
    return Question(a)
};